package com.weixing.mall.provider.controller.front;

import com.weixing.mall.base.wrapper.Result;
import com.weixing.mall.base.wrapper.ResultUtil;
import com.weixing.mall.base.enums.IsEnableEnum;
import com.weixing.mall.core.support.BaseController;
import com.weixing.mall.core.support.auth.MemAuth;
import com.weixing.mall.core.support.auth.MemInfo;
import com.weixing.mall.provider.model.dto.ads.MediaOrderdRecordDto;
import com.weixing.mall.provider.model.enums.AppointmentEunm;
import com.weixing.mall.provider.model.query.FrontMediaAdvertSingQuery;
import com.weixing.mall.provider.model.query.MediaLableQuery;
import com.weixing.mall.provider.model.query.MediaOrderRecordQuery;
import com.weixing.mall.provider.service.IMediaAdvertsingService;
import com.weixing.mall.provider.service.IMediaLabelService;
import com.weixing.mall.provider.service.IMediaOrderdRecordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.NonNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @ClassName FrontMediaOrderController
 * @Description TODO <br/>
 * @Author gjq
 * @Modified By:
 * @Date 2019/11/22
 * @Version 1.0
 **/
@RestController
@RequestMapping("front/mediaOrder")
@Api(value = "前端：广告预约api",tags = "前端：广告预约")
public class FrontMediaOrderController extends BaseController {

    @Autowired
    private IMediaAdvertsingService mediaAdvertsingService;
    @Autowired
    private IMediaOrderdRecordService mediaOrderdRecordService;
    @Autowired
    private IMediaLabelService mediaLabelService;

    @ApiOperation(value = "广告预约列表")
    @GetMapping("selectFrontOfPage")
    public Result selectFrontOfPage(@MemInfo MemAuth auth, FrontMediaAdvertSingQuery frontMediaAdvertSingQuery){
        return ResultUtil.success(mediaAdvertsingService.selectFrontOfPage(initMpPage(),frontMediaAdvertSingQuery,auth.getAbid()));
    }

    @ApiOperation(value = "广告详情/预约详情")
    @GetMapping("selectFrontDetil/{id}")
    public Result selectFrontDetil(@PathVariable("id") Long id){
        return ResultUtil.success(mediaAdvertsingService.selectFrontDetil(id));
    }

    @ApiOperation(value = "广告预约（新增不需要传id）")
    @PostMapping("save")
    public Result save(@MemInfo MemAuth auth,@RequestBody MediaOrderdRecordDto mediaOrderdRecordDto) throws Exception {
        mediaOrderdRecordService.saveMediaOrderdRecord(mediaOrderdRecordDto);
        return ResultUtil.success();
    }

    @ApiOperation(value = "我的预约 预约状态 1 已预约；2 已失败；3 已绑定；4 复审中；5 已取消；6 已排版；7 已投放 8 已收款；9 已推送")
    @GetMapping("selectMyMediaOrder")
    public Result selectMyMediaOrder(@MemInfo MemAuth auth,MediaOrderRecordQuery mediaOrderRecordQuery){
        return ResultUtil.success(mediaOrderdRecordService.selectMyMediaOrder(initMpPage(),mediaOrderRecordQuery,auth.getAbid()));
    }

    @ApiOperation(value = "取消预约（改变记录表状态为 5 已取消）")
    @GetMapping("changeRecordStatus")
    public Result changeRecordStatus(@NonNull Long id){
        mediaOrderdRecordService.changeRecordStatus(id, AppointmentEunm.STATUS5.getValue());
        return ResultUtil.success();
    }

    @ApiOperation(value = "查询媒体标签")
    @GetMapping("getMediaLable")
    public Result getList(){
        MediaLableQuery mediaLableQuery = new MediaLableQuery();
        mediaLableQuery.setIsEnable(IsEnableEnum.ENABLE.getValue());
        return ResultUtil.success(mediaLabelService.getList(mediaLableQuery));
    }
}
